$(function () {
	let orderSn = getQueryString("orderSn");
	let url = '../tranfer/list';
	if(orderSn){
		url = url + '?orderSn='+orderSn;
	}
    $("#jqGrid").Grid({
        url: url,
        colModel: [
			{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
		/*	{label: '申请用户id', name: 'userId', index: 'user_id', width: 80},
			{label: '申请店铺id', name: 'shopId', index: 'shop_id', width: 80},*/
			{label: '提现单号', name: 'orderSn', index: 'order_sn', width: 80},
			{label: '提现金额（元）', name: 'tranferMoney', index: 'tranfer_money', width: 80},
			{
				//'状态：0:处理中 1:已处理 2:未处理',
				label: '状态', name: 'status', index: 'status', width: 50, formatter: function (value) {
					if (value == '0') {
						return '处理中 ';
					} else if (value == '1') {
						return '已处理';
					} else if (value == '2') {
						return '未处理';
					}
					return value;
				}
			},
			{
				label: '提现凭证', name: 'voucherImg', index: 'voucher_img', width: 80, formatter: function (value) {
					return transImg(value);
				}
			},
			{label: '平台备注信息', name: 'adminRemarks', index: 'admin_remarks', width: 80},
			{label: '申请时间', name: 'applyTime', index: 'apply_time', width: 80,formatter: function (value) {
					return transDate(value);}},
			{label: '上次处理时间', name: 'lastdealTime', index: 'lastDeal_time', width: 80,formatter: function (value) {
					return transDate(value);}}

		]
    });
});

let vm = new Vue({
	el: '#rrapp',
	data: {
        showList: true,
        title: null,
		tranfer: {},
		ruleValidate: {
			name: [
				{required: true, message: '名称不能为空', trigger: 'blur'}
			]
		},
		q: {
		    orderSn: ''
		}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function () {
			vm.showList = false;
			vm.title = "新增";
			vm.tranfer = {};
		},
		update: function (event) {
            let id = getSelectedRow("#jqGrid");
			if (id == null) {
				return;
			}
			vm.showList = false;
            vm.title = "修改";
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
            let url = vm.tranfer.id == null ? "../tranfer/save" : "../tranfer/update";
            Ajax.request({
			    url: url,
                params: JSON.stringify(vm.tranfer),
                type: "POST",
			    contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
			});
		},
		del: function (event) {
            let ids = getSelectedRows("#jqGrid");
			if (ids == null){
				return;
			}

			confirm('确定要删除选中的记录？', function () {
                Ajax.request({
				    url: "../tranfer/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
				    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
					}
				});
			});
		},
		getInfo: function(id){
            Ajax.request({
                url: "../tranfer/info/"+id,
                async: true,
                successCallback: function (r) {
                    vm.tranfer = r.tranfer;
                }
            });
		},
		reload: function (event) {
			vm.showList = true;
            let page = $("#jqGrid").jqGrid('getGridParam', 'page');
			$("#jqGrid").jqGrid('setGridParam', {
                postData: {'orderSn': vm.q.orderSn},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
		},
        reloadSearch: function() {
            vm.q = {
                orderSn: ''
            }
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
		handleSuccess: function (res, file) {
			vm.tranfer.voucherImg = file.response.url;
		},
		eyeImage: function () {
			var url = vm.tranfer.voucherImg;
			eyeImage(url);
		},
		handleFormatError: function (file) {
			this.$Notice.warning({
				title: '文件格式不正确',
				desc: '文件 ' + file.name + ' 格式不正确，请上传 jpg 或 png 格式的图片。'
			});
		},
		handleMaxSize: function (file) {
			this.$Notice.warning({
				title: '超出文件大小限制',
				desc: '文件 ' + file.name + ' 太大，不能超过 2M。'
			});
		},
        handleReset: function (name) {
            handleResetForm(this, name);
        }
	}
});